package com.innoking.docsys.controller;


import com.innoking.docsys.user.module.UpmsUserVO;
import com.innoking.docsys.utils.*;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/jwt")
public class JwtController {

    @PostMapping("/getJwt")
    public ResultObjVO getJwt(@RequestBody String data){

        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new UpmsUserVO() );
        UpmsUserVO tbUserVo= (UpmsUserVO) ob.getObj();

        long loginId = tbUserVo.getUserId();
        if( loginId>0) {

           //给用户jwt加密生成token
           String token = JWTUtil.sign(loginId, 60L* 1000L* 30L);

           //封装成对象返回给客户端
           return    ResultUtil.success(token);
        }
        else{
         return    ResultUtil.tokenError();
        }



    }
}